{extend name="index/base" /}
{block name="content"}
<style type="text/css">
    .item{
        margin-left: 0;
    }
    .domain{
        width: 400px;
        margin: 2px 0;
        display: inline;
    }
</style>
<div>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">dll</label>
            <div class="layui-input-block">
                <a href="javascript:;" class="layui-btn" id="dllAddBtn">添加</a>
            </div>
            <div class="layui-input-block" id="dllBox">

            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="开启"  checked>
                <input type="radio" name="status" value="0" title="禁用">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{$id}">
                <a class="layui-btn" lay-submit lay-filter="submit">提交</a>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="js"}
<script type="text/javascript">
    layui.use(['table','jquery','form','upload'], function(){
        var table = layui.table; var form = layui.form;var upload = layui.upload;
        var $ = layui.$;
        form.on('submit(submit)', function(data){
            console.log(data.field);
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post("{:url('editTackledlls')}", data.field, function (res) {
                layer.close(loading);
                if (res.code == 0) {
                    layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                        window.parent.location.reload();
                        return false;
                    });
                } else {
                    layer.msg(res.msg, {time: 1800, icon: 2});
                }
            });
        });

        var dllIndex = 0;
        $('#dllAddBtn').click(function(){
            var str = '';
            str += '<div class="layui-input-block item"><input type="text" class="layui-input domain" name="dll[]" placeholder="dll"> ';
            str += '<a class="layui-btn layui-btn-xs layui-btn-danger" id="dll_'+dllIndex+'_delBtn">删除</a>';
            str += '</div>';

            $('#dllBox').append(str);

            $('#dll_'+dllIndex+'_delBtn').click(function(){
                $(this).parent().remove();
            })
            dllIndex++;
        });

        $.post('{:url("getTackledlls")}',{id:'{$id}'},function(res){
            if(res.code==0) {
                $.each(res.data.dll, function(index, o){
                    var str = '';
                    str += '<div class="layui-input-block item"><input type="text" class="layui-input domain" name="dll[]" placeholder="dll" value="'+o+'"> ';
                    str += '<a class="layui-btn layui-btn-xs layui-btn-danger" id="dll_'+dllIndex+'_delBtn">删除</a>';
                    str += '</div>';

                    $('#dllBox').append(str);

                    $('#dll_'+dllIndex+'_delBtn').click(function(){
                        $(this).parent().remove();
                    })
                    dllIndex++;
                })
            }
        });
    });
</script>
{/block}